import 'package:flutter_deer/database/beans/get_user_info_entity.dart';
import 'package:flutter_deer/database/beans/pay/create_order_entity.dart';
import 'package:flutter_deer/generated/json/base/json_convert_content.dart';

class CreateOrderEntity {
  String discountAmount = ""; // 优惠金额
  List<Discount> discounts = [];
  EnergyGoods? energyGoods;
  String mchCode = GetUserInfoEntity.get()?.loginMerchantCode?? '';
  String mchMemberId = "";
  PayInfo payInfo = PayInfo();
  bool useCoupon = false;
  String? useIntegral;
  bool douYinPay = false;
  String staffId = ""; // 员工id
  String staffName = ""; // 员工名字
  String orderId = ""; // 第二次混合支付传
  String orderFinanceId = ""; // 第二次混合支付传
  bool compositePay = false; // 混合支付
  List<StoreGoodsInfos> storeGoodsInfos = []; // 便利店商品、混合支付不可用
  String terminalNo = ""; // 拉卡拉
  int? couponSelectType;
  List<String>? energyOrderIds; // 零管专用字段
  String? memberPlateNo; // 车牌号支付
  // 线下优惠字段
  CreateOrderOfflineDiscounts? offlineDiscounts;
  String? offlineDiscountsAmount; // 线下优惠最终金额
  bool useIntegralToCash = false;
  String posVersion = "v1";

  CreateOrderEntity();

  factory CreateOrderEntity.fromJson(Map<String, dynamic> json) => $CreateOrderEntityFromJson(json);
  Map<String, dynamic> toJson() => $CreateOrderEntityToJson(this);
}

Map<String, dynamic> $CreateOrderEntityToJson(CreateOrderEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['discountAmount'] = entity.discountAmount;
  data['discounts'] = entity.discounts.map((v) => v.toJson()).toList();
  data['energyGoods'] = entity.energyGoods?.toJson();
  data['mchCode'] = entity.mchCode;
  data['mchMemberId'] = entity.mchMemberId;
  data['payInfo'] = entity.payInfo.toJson();
  data['useCoupon'] = entity.useCoupon;
  data['useIntegral'] = entity.useIntegral;
  data['douYinPay'] = entity.douYinPay;
  data['staffId'] = entity.staffId;
  data['staffName'] = entity.staffName;
  data['orderId'] = entity.orderId;
  data['orderFinanceId'] = entity.orderFinanceId;
  data['compositePay'] = entity.compositePay;
  data['storeGoodsInfos'] = entity.storeGoodsInfos.map((v) => v.toJson()).toList();
  data['terminalNo'] = entity.terminalNo;
  data['couponSelectType'] = entity.couponSelectType;
  data['energyOrderIds'] = entity.energyOrderIds;
  data['memberPlateNo'] = entity.memberPlateNo;
  data['offlineDiscounts'] = entity.offlineDiscounts?.toJson();
  data['offlineDiscountsAmount'] = entity.offlineDiscountsAmount;
  data['useIntegralToCash'] = entity.useIntegralToCash;
  data['posVersion'] = entity.posVersion;
  return data;
}

CreateOrderEntity $CreateOrderEntityFromJson(Map<String, dynamic> json) {
  final CreateOrderEntity createOrderEntity = CreateOrderEntity();
  final String? discountAmount = jsonConvert.convert<String>(json['discountAmount']);
  if (discountAmount != null) {
    createOrderEntity.discountAmount = discountAmount;
  }
  final List<Discount>? discounts = (json['discounts'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<Discount>(e) as Discount).toList();
  if (discounts != null) {
    createOrderEntity.discounts = discounts;
  }
  final EnergyGoods? energyGoods = jsonConvert.convert<EnergyGoods>(json['energyGoods']);
  if (energyGoods != null) {
    createOrderEntity.energyGoods = energyGoods;
  }
  final String? mchCode = jsonConvert.convert<String>(json['mchCode']);
  if (mchCode != null) {
    createOrderEntity.mchCode = mchCode;
  }
  final String? mchMemberId = jsonConvert.convert<String>(json['mchMemberId']);
  if (mchMemberId != null) {
    createOrderEntity.mchMemberId = mchMemberId;
  }
  final PayInfo? payInfo = jsonConvert.convert<PayInfo>(json['payInfo']);
  if (payInfo != null) {
    createOrderEntity.payInfo = payInfo;
  }
  final bool? useCoupon = jsonConvert.convert<bool>(json['useCoupon']);
  if (useCoupon != null) {
    createOrderEntity.useCoupon = useCoupon;
  }
  final String? useIntegral = jsonConvert.convert<String>(json['useIntegral']);
  if (useIntegral != null) {
    createOrderEntity.useIntegral = useIntegral;
  }
  final bool? douYinPay = jsonConvert.convert<bool>(json['douYinPay']);
  if (douYinPay != null) {
    createOrderEntity.douYinPay = douYinPay;
  }
  final String? staffId = jsonConvert.convert<String>(json['staffId']);
  if (staffId != null) {
    createOrderEntity.staffId = staffId;
  }
  final String? staffName = jsonConvert.convert<String>(json['staffName']);
  if (staffName != null) {
    createOrderEntity.staffName = staffName;
  }
  final String? orderId = jsonConvert.convert<String>(json['orderId']);
  if (orderId != null) {
    createOrderEntity.orderId = orderId;
  }
  final String? orderFinanceId = jsonConvert.convert<String>(json['orderFinanceId']);
  if (orderFinanceId != null) {
    createOrderEntity.orderFinanceId = orderFinanceId;
  }
  final bool? compositePay = jsonConvert.convert<bool>(json['compositePay']);
  if (compositePay != null) {
    createOrderEntity.compositePay = compositePay;
  }
  final List<StoreGoodsInfos>? storeGoodsInfos = (json['storeGoodsInfos'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<StoreGoodsInfos>(e) as StoreGoodsInfos).toList();
  if (storeGoodsInfos != null) {
    createOrderEntity.storeGoodsInfos = storeGoodsInfos;
  }
  final String? terminalNo = jsonConvert.convert<String>(json['terminalNo']);
  if (terminalNo != null) {
    createOrderEntity.terminalNo = terminalNo;
  }
  final int? couponSelectType = jsonConvert.convert<int>(json['couponSelectType']);
  if (couponSelectType != null) {
    createOrderEntity.couponSelectType = couponSelectType;
  }
  final List<String>? energyOrderIds = (json['energyOrderIds'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<String>(e) as String).toList();
  if (energyOrderIds != null) {
    createOrderEntity.energyOrderIds = energyOrderIds;
  }
  final String? memberPlateNo = jsonConvert.convert<String>(json['memberPlateNo']);
  if (memberPlateNo != null) {
    createOrderEntity.memberPlateNo = memberPlateNo;
  }
  final CreateOrderOfflineDiscounts? offlineDiscounts = jsonConvert.convert<CreateOrderOfflineDiscounts>(json['offlineDiscounts']);
  if (offlineDiscounts != null) {
    createOrderEntity.offlineDiscounts = offlineDiscounts;
  }
  final String? offlineDiscountsAmount = jsonConvert.convert<String>(json['offlineDiscountsAmount']);
  if (offlineDiscountsAmount != null) {
    createOrderEntity.offlineDiscountsAmount = offlineDiscountsAmount;
  }
  final bool? useIntegralToCash = jsonConvert.convert<bool>(json['useIntegralToCash']);
  if (useIntegralToCash != null) {
    createOrderEntity.useIntegralToCash = useIntegralToCash;
  }
  final String? posVersion = jsonConvert.convert<String>(json['posVersion']);
  if (posVersion != null) {
    createOrderEntity.posVersion = posVersion;
  }
  return createOrderEntity;
}